package com.tao.controller;


import com.tao.dto.MyResult;
import com.tao.dto.PageResult;
import com.tao.dto.SuccessResult;
import com.tao.entity.Member;
import com.tao.entity.RegisterCode;
import com.tao.service.MemberService;
import com.tao.service.RegisterCodeService;
import com.tao.util.CodeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="注册码controller",tags={"注册码"})
@RestController
@CrossOrigin
public class RegisterCodeController {

    @Autowired
    RegisterCodeService registerCodeService;




    @ApiOperation("注册码增加")
    @PostMapping("/code/add")
    public MyResult add(@RequestBody RegisterCode registerCode){
        registerCode.setCode(CodeUtil.giveCode());
        RegisterCode insert = registerCodeService.insert(registerCode);
        return new SuccessResult("新增成功",insert);
    }

    @ApiOperation("注册码获取")
    @GetMapping("/code/getALL")
    public MyResult getAll( Integer page,Integer size,RegisterCode registerCode){
        PageResult all = registerCodeService.findAll(registerCode, page-1, size);
        return new SuccessResult("获取成功",all);
    }

    @ApiOperation("注册码删除")
    @DeleteMapping("/code/del/{id}")
    public MyResult del(@PathVariable("id") Integer id){
        registerCodeService.delete(id);
        return new SuccessResult("删除成功",null);
    }




}
